package com.augurit.wf.bi.convert;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.augurit.common.util.lang.DateUtils;
import com.augurit.wf.bi.web.form.WfBusInstanceForm;
import com.augurit.wf.bi.web.form.WfBusInstanceTaskForm;
import com.augurit.wf.common.entity.WfBusInstance;

public class WfBusInstanceConvertor {
	public static WfBusInstanceForm convertVoToForm(WfBusInstance entity) {
		if(entity != null) {
			WfBusInstanceForm form = new WfBusInstanceForm();
			form.setWfBusInstanceId(entity.getWfBusInstanceId());
			form.setMasterEntity(entity.getMasterEntity());
			form.setMasterEntityKey(entity.getMasterEntityKey());
			form.setProcInstId(entity.getProcInstId());
			form.setTemplateId(entity.getTemplateId());
			form.setBusMemo1(entity.getBusMemo1());
			form.setBusMemo2(entity.getBusMemo2());
			form.setBusMemo3(entity.getBusMemo3());
			form.setBusMemo4(entity.getBusMemo4());
			form.setBusMemo5(entity.getBusMemo5());
			form.setBusMemo6(entity.getBusMemo6());
			form.setBusMemo7(entity.getBusMemo7());
			form.setBusMemo8(entity.getBusMemo8());
			form.setBusMemo9(entity.getBusMemo9());
			form.setBusMemo10(entity.getBusMemo10());
			form.setBusDate1(entity.getBusDate1());
			form.setBusDate2(entity.getBusDate2());
			form.setBusDate3(entity.getBusDate3());
			form.setBusDate4(entity.getBusDate4());
			form.setBusNum1(entity.getBusNum1());
			form.setBusNum2(entity.getBusNum2());
			return form;
		}else
			return null;
	}
	
	public static WfBusInstanceTaskForm convertVoToTaskForm(WfBusInstance entity) {
		if(entity != null) {
			WfBusInstanceTaskForm form = new WfBusInstanceTaskForm();
			form.setWfBusInstanceId(entity.getWfBusInstanceId());
			form.setMasterEntity(entity.getMasterEntity());
			form.setMasterEntityKey(entity.getMasterEntityKey());
			form.setProcInstId(entity.getProcInstId());
			form.setTemplateId(entity.getTemplateId());
			return form;
		}else
			return null;
	}
	
	public static void convertFormToVo(WfBusInstanceForm form, WfBusInstance entity) {
		if(entity != null && form != null) {
			entity.setWfBusInstanceId(form.getWfBusInstanceId());
			if(form.getMasterEntity() != null && form.getMasterEntity().trim().length() > 0)
				entity.setMasterEntity(form.getMasterEntity().trim());
			if(form.getMasterEntityKey() != null && form.getMasterEntityKey().trim().length() > 0)
				entity.setMasterEntityKey(form.getMasterEntityKey().trim());
			if(form.getProcInstId() != null && form.getProcInstId().trim().length() > 0)
				entity.setProcInstId(form.getProcInstId().trim());
			if(form.getTemplateId() != null )
				entity.setTemplateId(form.getTemplateId());
			if(form.getBusMemo1() != null && form.getBusMemo1().trim().length() > 0)
				entity.setBusMemo1(form.getBusMemo1().trim());
			if(form.getBusMemo2() != null && form.getBusMemo2().trim().length() > 0)
				entity.setBusMemo2(form.getBusMemo2().trim());
			if(form.getBusMemo3() != null && form.getBusMemo3().trim().length() > 0)
				entity.setBusMemo3(form.getBusMemo3().trim());
			if(form.getBusMemo4() != null && form.getBusMemo4().trim().length() > 0)
				entity.setBusMemo4(form.getBusMemo4().trim());
			if(form.getBusMemo5() != null && form.getBusMemo5().trim().length() > 0)
				entity.setBusMemo5(form.getBusMemo5().trim());
			if(form.getBusMemo6() != null && form.getBusMemo6().trim().length() > 0)
				entity.setBusMemo6(form.getBusMemo6().trim());
			if(form.getBusMemo7() != null && form.getBusMemo7().trim().length() > 0)
				entity.setBusMemo7(form.getBusMemo7().trim());
			if(form.getBusMemo8() != null && form.getBusMemo8().trim().length() > 0)
				entity.setBusMemo8(form.getBusMemo8().trim());
			if(form.getBusMemo9() != null && form.getBusMemo9().trim().length() > 0)
				entity.setBusMemo9(form.getBusMemo9().trim());
			if(form.getBusMemo10() != null && form.getBusMemo10().trim().length() > 0)
				entity.setBusMemo10(form.getBusMemo10().trim());
			if(form.getBusDate1() != null )
				entity.setBusDate1(form.getBusDate1());
			if(form.getBusDate2() != null )
				entity.setBusDate2(form.getBusDate2());
			if(form.getBusDate3() != null )
				entity.setBusDate3(form.getBusDate3());
			if(form.getBusDate4() != null )
				entity.setBusDate4(form.getBusDate4());
			if(form.getBusNum1() != null )
				entity.setBusNum1(form.getBusNum1());
			if(form.getBusNum2() != null )
				entity.setBusNum2(form.getBusNum2());
		}
	}
	
	public static List<WfBusInstanceForm> convertVoListToFormList(List<WfBusInstance> wfBusInstanceList) {
		if(wfBusInstanceList != null && wfBusInstanceList.size() > 0) {
			List<WfBusInstanceForm> wfBusInstanceFormList = new ArrayList();
			for(int i=0; i<wfBusInstanceList.size(); i++) {
				wfBusInstanceFormList.add(convertVoToForm(wfBusInstanceList.get(i)));
			}
			return wfBusInstanceFormList;
		}
		return null;
	}
	
	public static List<WfBusInstance> convertFormListToVoList(List<WfBusInstanceForm> wfBusInstanceFormList) {
		if(wfBusInstanceFormList != null && wfBusInstanceFormList.size() > 0) {
			List<WfBusInstance> wfBusInstanceList = new ArrayList();
			for(int i=0; i<wfBusInstanceFormList.size(); i++) {
				WfBusInstance wfBusInstance = new WfBusInstance();
				convertFormToVo(wfBusInstanceFormList.get(i), wfBusInstance);
				wfBusInstanceList.add(wfBusInstance);
			}
			return wfBusInstanceList;
		}
		return null;
	}
}